package org.example.controller;


import lombok.extern.slf4j.Slf4j;
import org.example.comment.utils.ThreadLocalUtil;
import org.example.entity.dto.MessageDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.example.service.AiChatAgent;


@Slf4j
@RestController
@RequestMapping("/aiChatAgent")
public class AiChatAgentController {

    @Autowired
    private AiChatAgent aiChatAgent;

    @PostMapping("/chat")
    public String chat(@RequestBody MessageDto messageDto) {
//        Long userId = messageDto.getUserId();
        // 从ThreadLocal中获取用户ID，进行数据隔离
        Long userId = ThreadLocalUtil.get();
        String message = messageDto.getMessage();
        log.info("userId: {}, message: {}", userId, message);
        String answer = aiChatAgent.chat(userId, message);
        return answer;
    }
}
